package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Region;
import cn.wolfcode.luowowo.article.mapper.DestinationMapper;
import cn.wolfcode.luowowo.article.mapper.RegionMapper;
import cn.wolfcode.luowowo.article.service.IRegionService;
import cn.wolfcode.luowowo.common.query.RegionQuery;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService {

    @Autowired
    private RegionMapper regionMapper;
    @Autowired
    private DestinationMapper destinationMapper;

    public PageInfo query(RegionQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<Region> list = regionMapper.selectForList(qo);
        return new PageInfo(list);
    }

    public void saveOrUpdate(Region region) {
        if (region.getId() != null) {
            regionMapper.updateByPrimaryKey(region);
        } else {
            regionMapper.insert(region);
        }
    }

    public List<Region> listHotRegions() {
        List<Region> regions = regionMapper.selectHotRegions();
        return regions;
    }

}
